package com.ylr.blog.common.enums;

import com.ylr.base.common.dto.NameValue;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.ToString;

import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 * Created by IntelliJ IDEA.
 *
 * @author wyw
 * date: 2023-05-24 21:22:32
 * className: AuditBlogFlowEnum
 * version: 1.0
 * description:
 */
@Getter
@ToString
@AllArgsConstructor
public enum AuditBlogFlowEnum {

    /*
        博客审核流水表字段枚举值
     */
    // 类型[0-分单 1-委托 2-复审 3-转派 4-审核通过 5-审核拒绝 6-复审通过 7-复审拒绝 8-撤销审核]
    ASSIGN(0, "分单"),
    ENTRUST(1, "委托"),
    RECHECK(2, "复审"),
    TRANSFER(3, "转派"),
    CHECK_PASS(4, "审核通过"),
    CHECK_REJECT(5, "审核拒绝"),
    RECHECK_PASS(6, "复审通过"),
    RECHECK_REJECT(7, "复审拒绝"),
    WITHDRAW(8, "撤销审核"),
    ;

    /**
     * 值
     */
    private final Integer value;

    /**
     * 名称
     */
    private final String name;

    /**
     * 获取类型枚举数组
     */
    public static AuditBlogFlowEnum[] getTypeEnums() {
        return new AuditBlogFlowEnum[] {
                ASSIGN,
                ENTRUST,
                RECHECK,
                TRANSFER,
                CHECK_PASS,
                CHECK_REJECT,
                RECHECK_PASS,
                RECHECK_REJECT,
                WITHDRAW
        };
    }

    /**
     * 获取类型枚举列表
     */
    public static List<NameValue<Integer>> getTypeEnumList() {
        return Stream.of(getTypeEnums())
                .map(typeEnum -> new NameValue<>(typeEnum.name, typeEnum.value))
                .collect(Collectors.toList());
    }

    /**
     * 获取类型枚举对象
     * @param value 参数值
     * @return 类型枚举对象
     */
    public static AuditBlogFlowEnum getTypeEnum(Integer value) {
        for (AuditBlogFlowEnum typeEnum : getTypeEnums()) {
            if (typeEnum.value.equals(value)) {
                return typeEnum;
            }
        }
        return null;
    }

    /**
     * 校验类型值是否正确
     * @param value 参数值
     * @return true-校验拒绝 false-校验通过
     */
    public static boolean isTypeFail(Integer value) {
        return Objects.isNull(getTypeEnum(value));
    }
}
